package com.nexus.all.convertor;

import com.nexus.all.model.FileBatch;
import com.nexus.all.dto.FileBatchDTO;
import com.nexus.all.vo.FileBatchVO;
import org.springframework.cglib.beans.BeanCopier;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 文件批次对象相互转换
 *
 * @author zxt
 * @version 1.0
 * @CopyRright (c): <?>
 */
public abstract class FileBatchConvertor {

    private static final BeanCopier beanCopierForFileBatchVO = BeanCopier.create(FileBatch.class, FileBatchVO.class, false);
    private static final BeanCopier beanCopierForFileBatch = BeanCopier.create(FileBatchDTO.class, FileBatch.class, false);

    public static FileBatchVO toFileBatchVO(FileBatch fileBatch) {
        if (Objects.isNull(fileBatch)) {
            return null;
        }
        FileBatchVO fileBatchVO = new FileBatchVO();
        beanCopierForFileBatchVO.copy(fileBatch, fileBatchVO, null);
        return fileBatchVO;
    }

    public static FileBatch toFileBatch(FileBatchDTO fileBatchDTO) {
        FileBatch fileBatch = new FileBatch();
        beanCopierForFileBatch.copy(fileBatchDTO, fileBatch, null);
        return fileBatch;
    }

    public static List<FileBatchVO> toFileBatchVOList(List<FileBatch> fileBatchList) {
        if (Objects.isNull(fileBatchList) || fileBatchList.isEmpty()) {
            return new ArrayList<>();
        }
        List<FileBatchVO> fileBatchInfoList = new ArrayList<FileBatchVO>(fileBatchList.size());
        for (FileBatch fileBatch : fileBatchList) {
            fileBatchInfoList.add(toFileBatchVO(fileBatch));
        }
        return fileBatchInfoList;
    }

    public static List<FileBatch> toFileBatchList(List<FileBatchDTO> fileBatchDTOList) {
        if (Objects.isNull(fileBatchDTOList) || fileBatchDTOList.isEmpty()) {
            return new ArrayList<>();
        }
        List<FileBatch> fileBatchList = new ArrayList<FileBatch>(fileBatchDTOList.size());
        for (FileBatchDTO fileBatchDTO : fileBatchDTOList) {
            fileBatchList.add(toFileBatch(fileBatchDTO));
        }
        return fileBatchList;
    }

}
